//
//  QZHomeADCell.m
//  shortvideoplay
//
//  Created by adam on 2024/8/6.
//

#import "QZHomeADCell.h"
#import "JPVideoPlayerKit.h"
#import <AVFoundation/AVFoundation.h>
#import "BVideoCacheTool.h"
#import "SJProgressSlider.h"
#import "QZVideoPlaySliderView.h"
#import "DJJubaoVC.h"
#import "CommentsPopView.h"
#import "SharePopView.h"
#import "UIImage+Compression.h"
#import "ZFSliderView.h"
#import "NSAttributedString+YYText.h"
#import "DJMYBIVC.h"

static const NSInteger kAwemeListLikeCommentTag = 0x01;
static const NSInteger kAwemeListLikeShareTag   = 0x02;
static const NSInteger kAwemeListLikeCollectionTag   = 0x03;
static const NSInteger kAwemeListLikeHuaTag   = 0x04;

@interface QZHomeADCell ()<JPVideoPlayerDelegate,UIGestureRecognizerDelegate,SendTextDelegate, HoverTextViewDelegate, AVPlayerUpdateDelegate,SharePopViewDelegate,ZFSliderViewDelegate>

@property (nonatomic,assign) BVideoCacheResult playCacheResult;//判断是否是缓存

@property (strong, nonatomic) QZVideoPlaySliderView * slider;
@property (strong, nonatomic)  UILabel *home_recommend_title;//标题
@property (strong, nonatomic)  UILabel *home_recommend_subTitle;//子标题

@property (strong, nonatomic)  AVPlayer *player;
@property (strong, nonatomic)  AVPlayerItem * pushplayerItem;
@property (strong, nonatomic)  AVPlayerLayer *playerLayer;


/*第二版本*/

@property (nonatomic, strong) UIView                   *container;

//@property (nonatomic ,strong) UIImageView              *musicIcon;
@property (nonatomic, assign) NSTimeInterval           lastTapTime;
@property (nonatomic, assign) CGPoint                  lastTapPoint;
@property (nonatomic, assign) CGFloat                  cellHeight;
@property (nonatomic, assign) BOOL                  isTouch;

@end
@implementation QZHomeADCell

- (void)showOldAddNavViewToMainOldView1{
    UIView * oldBgSS = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    oldBgSS.clipsToBounds = YES;
    [self addSubview:oldBgSS];
    
    UIButton * sendBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreen_W-75, kStatusBarHeight+10, 60, 46)];
    sendBtn.layer.cornerRadius = 3;
    sendBtn.backgroundColor = [UIColor whiteColor];
    [sendBtn setTitle:@"发送" forState:UIControlStateNormal];
    [sendBtn setTitleColor:ColorHex(@"#333333") forState:UIControlStateNormal];
    sendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [sendBtn addTarget:self action:@selector(sendTap) forControlEvents:UIControlEventTouchUpInside];
    [oldBgSS addSubview:sendBtn];
    
    UIView * sendBg = [[UIView alloc]initWithFrame:CGRectMake(15, kStatusBarHeight+66, KScreen_W-30, (KScreen_H-KSafeAreaBottomHeight-25-(kStatusBarHeight+66))/2)];
    sendBg.backgroundColor = [UIColor whiteColor];
    sendBg.layer.cornerRadius = 3;
    [oldBgSS addSubview:sendBg];
    
    UILabel * sendTip = [[UILabel alloc]initWithFrame:CGRectMake(0, (sendBg.frame.size.height-40)/2, sendBg.frame.size.width, 40)];
    sendTip.text = @"发送区";
    sendTip.textColor = ColorHex(@"#f0f0f0");
    sendTip.textAlignment = NSTextAlignmentCenter;
    sendTip.font = [UIFont systemFontOfSize:28];
    [sendBg addSubview:sendTip];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    UIImageView * showTextViewImgTo2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
    showTextViewImgTo2.hidden = YES;
    showTextViewImgTo2.layer.cornerRadius = K_AUTOLAYOUT_W(30);
    showTextViewImgTo2.clipsToBounds = YES;
    showTextViewImgTo2.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:showTextViewImgTo2];
    
    UILabel * showTextViewLabelTo2 = [[UILabel alloc]initWithFrame:CGRectMake(15, 35, KScreen_W-30, 30)];
    showTextViewLabelTo2.hidden = YES;
    showTextViewLabelTo2.font = FontBold(18);
    showTextViewLabelTo2.textColor = ThreeColor;
    showTextViewLabelTo2.textAlignment = NSTextAlignmentCenter;
    [self addSubview:showTextViewLabelTo2];
    // Initialization code
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        self.backgroundColor = viewback_black;
        self.cellHeight = frame.size.height;
        _lastTapTime = 0;
        _lastTapPoint = CGPointZero;
        [self initSubViews];
        self.clipsToBounds = YES;
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
}

- (void)initSubViews {
    //init player view;
    
    //init hover on player view container
    _container = [UIView new];
    [self.contentView addSubview:_container];
    
    
    
    KWeakSelf

    _ADPlayView = [[UIView alloc]init];
    _ADPlayView.backgroundColor = viewback_black;
    [_container addSubview:_ADPlayView];
    
    _share = [[UIImageView alloc]init];
    _share.contentMode = UIViewContentModeCenter;
    _share.image = [UIImage imageNamed:@"share"];
    _share.userInteractionEnabled = YES;
    _share.tag = kAwemeListLikeShareTag;
    [_share addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_share];
    
    _shareNum = [[UILabel alloc]init];
    _shareNum.text = @"0";
    _shareNum.textColor = [UIColor whiteColor];
    _shareNum.font = Font(12);
    [_container addSubview:_shareNum];
    
    _hua = [[UIImageView alloc]init];
    _hua.contentMode = UIViewContentModeCenter;
    _hua.image = [UIImage imageNamed:@"share"];
    _hua.userInteractionEnabled = YES;
    _hua.tag = kAwemeListLikeHuaTag;
    [_hua addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_hua];
    
    _huaNum = [[UILabel alloc]init];
    _huaNum.text = @"送花";
    _huaNum.textColor = [UIColor whiteColor];
    _huaNum.font = Font(12);
    [_container addSubview:_huaNum];
    
    _collectionNum = [[UILabel alloc]init];
    _collectionNum.text = @"0";
    _collectionNum.textColor = [UIColor whiteColor];
    _collectionNum.font = Font(12);
    [_container addSubview:_collectionNum];
    
    _collection = [[UIImageView alloc]init];
    _collection.contentMode = UIViewContentModeCenter;
    _collection.image = [UIImage imageNamed:@"home_video_collection_nor"];
    _collection.userInteractionEnabled = YES;
    _collection.tag = kAwemeListLikeCollectionTag;
    [_collection addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_collection];
    
    _comment = [[UIImageView alloc]init];
    _comment.contentMode = UIViewContentModeCenter;
    _comment.image = [UIImage imageNamed:@"comment"];
    _comment.userInteractionEnabled = YES;
    _comment.tag = kAwemeListLikeCommentTag;
    [_comment addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]];
    [_container addSubview:_comment];
    
    _commentNum = [[UILabel alloc]init];
    _commentNum.text = @"0";
    _commentNum.textColor = [UIColor whiteColor];
    _commentNum.font = Font(12);
    [_container addSubview:_commentNum];
    
    _favorite = [FavoriteView new];
    [_container addSubview:_favorite];
    
    _favoriteNum = [[UILabel alloc]init];
    _favoriteNum.text = @"0";
    _favoriteNum.textColor = [UIColor whiteColor];
    _favoriteNum.font = Font(12);
    [_container addSubview:_favoriteNum];
    
    //init avatar
    CGFloat avatarRadius = 25;
    _avatar = [[UIImageView alloc] init];
    _avatar.image = [UIImage imageNamed:@"ic_head_defuls"];
    _avatar.layer.cornerRadius = avatarRadius;
    _avatar.layer.borderColor = COLOR_ALPH(255.0, 255.0, 255.0, 0.8).CGColor;
    _avatar.layer.borderWidth = 1;
    _avatar.clipsToBounds = YES;
    [_container addSubview:_avatar];
    
    //init focus action
    _focus = [FocusView new];
    [_container addSubview:_focus];
    
   

    
//    [_hoverTextView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_offset(15);
//        make.right.mas_offset(-15);
//        make.height.mas_offset(44);
//        make.bottom.equalTo(self).mas_offset(47);
//    }];
    [_ADPlayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];

    [_container mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.bottom.mas_offset(0);
    }];
   
    [_share mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.container.mas_bottom).offset(-105);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_shareNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.share.mas_bottom);
        make.centerX.equalTo(self.share);
    }];
    
    [_hua mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.share.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_huaNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.comment.mas_bottom);
        make.centerX.equalTo(self.comment);
    }];
    
    [_comment mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.hua.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    [_commentNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.comment.mas_bottom);
        make.centerX.equalTo(self.comment);
    }];
    
    
    [_collection mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.comment.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    
    [_collectionNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.collection.mas_bottom);
        make.centerX.equalTo(self.collection);
    }];
    
    [_favorite mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.collection.mas_top).offset(-25);
        make.right.equalTo(self).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(45);
    }];
    
    [_favoriteNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.favorite.mas_bottom);
        make.centerX.equalTo(self.favorite);
    }];
    
    [_avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.favorite.mas_top).offset(-35);
        make.right.equalTo(self).offset(-10);
        make.width.height.mas_equalTo(avatarRadius*2);
    }];
    [_focus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.avatar);
        make.centerY.equalTo(self.avatar.mas_bottom);
        make.width.height.mas_equalTo(24);
    }];
    _focus.myFollowFoucusBlock = ^(NSInteger index) {
        if(index == 0){
            [weakSelf followsUser];
        }
    };
    _favorite.myLikeFavoriteBlock = ^(NSInteger index) {
        if(index == 0){
            [weakSelf likeVideo:NO];
        }else if(index == 1){
            [weakSelf likeVideo:NO];
        }
    };
    
    _avatar.userInteractionEnabled = YES;
    [_avatar addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handToUserInfo)]];
}
#pragma mark 事件区域
- (void)handToUserInfo{
    if(self.videoModel.is_ADView){
        return;
    }
    if([QZUserInfoModel isLogin] == NO){
        [QZUserInfoModel presentLoginView];
        return;
    }
    if([self.videoModel.mid integerValue] == [[QZUserInfoModel share].mid integerValue]){
        //自己
        return;
    }
    [QZUserInfoModel otherMineControlView:[Tools currentActiveController] mineId:self.videoModel.mid videoId:self.videoModel.videoid];
}
- (void)followsUser{
    KWeakSelf
    KMutableDic(sendDic)
    [sendDic setObject:_videoModel.mid forKey:@"to_mid"];
    [YBNetBase userFollowUserRequest:sendDic target:[Tools currentActiveController] successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            if([weakSelf.videoModel.isfollow intValue] == 1){
                weakSelf.videoModel.isfollow = @(0);
                [YBMsgPop showPop:@"已取消关注"];
            }else{
                weakSelf.videoModel.isfollow = @(1);
//                [YBMsgPop showPop:NSLocalizedString(@"已关注", nil)];
            }
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
- (void)likeVideo:(BOOL)isDouble{
    KMutableDic(sendDic)
    KWeakSelf
    sendDic[@"videoid"] = self.videoModel.videoid;
    [YBNetBase videoLikeRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
        if(code == 200){
            
            weakSelf.videoModel.like_num = data[@"like_num"];
            weakSelf.videoModel.islike = data[@"islike"];
            [weakSelf.favoriteNum setText:[Tools NumberToShowString:[weakSelf.videoModel.like_num integerValue]]];
            [[QZDataUpdate share] updateLike:weakSelf.videoModel excludeTarget:[Tools currentActiveController]];
            if(isDouble){
                weakSelf.favorite.favoriteAfter.hidden = NO;
                return;
            }
           
        }else{
            [YBMsgPop showPop:msg];
        }
    }];
}
-(void)prepareForReuse {
    [super prepareForReuse];
    
    _isPlayerReady = NO;
//    [_pauseIcon setHidden:YES];
    
//    [_hoverTextView.textView setText:@""];
//    [_avatar setImage:[UIImage imageNamed:@"douyin"]];
    
//    [_musicAlum resetView];
    [_favorite resetView];
    [_focus resetView];
}

-(void)layoutSubviews {
    [super layoutSubviews];
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    [CATransaction commit];
}

//SendTextDelegate delegate
- (void)onSendText:(NSString *)text {
    

}

//HoverTextViewDelegate delegate
-(void)hoverTextViewStateChange:(BOOL)isHover {
    _container.alpha = isHover ? 0.0f : 1.0f;
}
-(BOOL)gestureRecognizer:
    (UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch{
   //若为UITableViewCellContentView（即点击了tableViewCell），则不截获Touch事件
    NSLog(@"%@", NSStringFromClass([touch.view class]));
    if([NSStringFromClass([touch.view class]) isEqualToString:@"YYLabel"]){
        self.isTouch = YES;
        return NO;
    }
   return YES;
  }
//gesture
- (void)handleGesture:(UITapGestureRecognizer *)sender {
    switch (sender.view.tag) {
        case kAwemeListLikeCollectionTag:{
            if(self.videoModel.is_ADView){
                return;
            }
            if([QZUserInfoModel isLogin] == NO){
                //没有登录
                [QZUserInfoModel presentLoginView];
                return;
            }
            KMutableDic(sendDic)
            sendDic[@"videoid"] = self.videoModel.videoid;
            KWeakSelf
            [YBNetBase videoCollectsRequest:sendDic successBlock:^(NSDictionary * _Nonnull data, NSInteger code, NSString * _Nonnull msg) {
                if(code == 200){
                    if([weakSelf.videoModel.iscollect boolValue]){
                        weakSelf.collection.image = KImageNamed(@"home_video_collection_nor");
                        weakSelf.videoModel.iscollect = @(0);
                        weakSelf.videoModel.collect_num = @([weakSelf.videoModel.collect_num intValue]-1);
                        
                    }else{
                        weakSelf.collection.image = KImageNamed(@"home_video_collection_sel");
                        weakSelf.videoModel.iscollect = @(1);
                        weakSelf.videoModel.collect_num = @([weakSelf.videoModel.collect_num intValue]+1);
                    }
                    [weakSelf.collectionNum setText:[Tools NumberToShowString:[weakSelf.videoModel.collect_num integerValue]]];
                    [[QZDataUpdate share] updateCollection:weakSelf.videoModel excludeTarget:[Tools currentActiveController]];
                }else{
                    [YBMsgPop showPop:msg];
                }
            }];
            break;
        }
        case kAwemeListLikeCommentTag: {
            if(self.videoModel.is_ADView){
                return;
            }
            if([QZUserInfoModel isLogin] == NO){
                //没有登录
                [QZUserInfoModel presentLoginView];
                return;
            }
            self.avatar.hidden = YES;
            self.focus.hidden = YES;
            self.favorite.hidden = YES;
            self.favoriteNum.hidden = YES;
            self.collection.hidden = YES;
            self.collectionNum.hidden = YES;
            self.comment.hidden = YES;
            self.commentNum.hidden = YES;
            self.share.hidden = YES;
            self.shareNum.hidden = YES;
            self.myPlayCommentBlock(0);
            break;
        }
        case kAwemeListLikeShareTag: {
            if(self.videoModel.is_ADView){
                return;
            }
            SharePopView *popView = [[SharePopView alloc] init];
            if([self.videoModel.mid integerValue] == [[QZUserInfoModel share].mid integerValue]){
                popView.bottomIconsName = @[@"ico_mine_more_share",@"ico_mine_more_download",@"ico_mine_more_delete"];
                popView.bottomTexts = @[@"分享",@"下载",@"删除"];
            }else{
                popView.bottomIconsName = @[@"ico_mine_more_share",@"ico_mine_more_jubao",@"ico_mine_more_notlike",@"ico_mine_more_download"];
                popView.bottomTexts = @[@"分享",@"举报",@"没兴趣",@"下载"];
            }
            popView.delegate = self;
            [popView show];
            break;
        }
        default: {
            NSLog(@"%@",sender.view);
            if(self.isTouch){
                self.isTouch = NO;
                return;
            }
            //获取点击坐标，用于设置爱心显示位置
            CGPoint point = [sender locationInView:_container];
            //获取当前时间
            NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970];
            //判断当前点击时间与上次点击时间的时间间隔
            if(time - _lastTapTime > 0.25f) {
                //推迟0.25秒执行单击方法
                [self performSelector:@selector(singleTapAction) withObject:nil afterDelay:0.25f];
            }else {
                //取消执行单击方法
                [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTapAction) object: nil];
                if(self.videoModel.is_ADView){
                    return;
                }
                if([QZUserInfoModel isLogin] == NO){
                    [QZUserInfoModel presentLoginView];
                    return;
                }
                if([self.videoModel.islike boolValue] == NO){
                    self.videoModel.islike = @(1);
                    [self likeVideo:YES];
                }
                //执行连击显示爱心的方法
                [self showLikeViewAnim:point oldPoint:_lastTapPoint];
            }
            //更新上一次点击位置
            _lastTapPoint = point;
            //更新上一次点击时间
            _lastTapTime =  time;
            break;
        }
    }
    
}
- (void)commentMoveStatus:(CGFloat)offset close:(BOOL)close{
    
}
- (void)singleTapAction {
    if([_hoverTextView isFirstResponder]) {
        [_hoverTextView resignFirstResponder];
    }else {
        
    }
}

//暂停播放动画
- (void)showPauseViewAnim:(CGFloat)rate {
   
   
}

//连击爱心动画
- (void)showLikeViewAnim:(CGPoint)newPoint oldPoint:(CGPoint)oldPoint {
    UIImageView *likeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"favAfter"]];
    CGFloat k = ((oldPoint.y - newPoint.y)/(oldPoint.x - newPoint.x));
    k = fabs(k) < 0.5 ? k : (k > 0 ? 0.5f : -0.5f);
    CGFloat angle = M_PI_4 * -k;
    likeImageView.frame = CGRectMake(newPoint.x, newPoint.y, 80, 80);
    likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 0.8f, 1.8f);
    [_container addSubview:likeImageView];
    [UIView animateWithDuration:0.2f
                          delay:0.0f
         usingSpringWithDamping:0.5f
          initialSpringVelocity:1.0f
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 1.0f, 1.0f);
                     }
                     completion:^(BOOL finished) {
                         [UIView animateWithDuration:0.5f
                                               delay:0.5f
                                             options:UIViewAnimationOptionCurveEaseOut
                                          animations:^{
                                              likeImageView.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(angle), 3.0f, 3.0f);
                                              likeImageView.alpha = 0.0f;
                                          }
                                          completion:^(BOOL finished) {
                                              [likeImageView removeFromSuperview];
                                          }];
                     }];
}

//加载动画
-(void)startLoadingPlayItemAnim:(BOOL)isStart {
}


// update method
//- (void)initData:(QZVideoModel *)data{
- (void)setVideoModel:(QZVideoModel *)videoModel{
    self.urlString = @"";
    [QZUserInfoModel share].adPlayId = videoModel.expressViewId;
    _ADPlayView.hidden = NO;
    _avatar.image = KImageNamed(@"ic_head_defuls");
    self.focus.hidden = NO;
    _favorite.favoriteAfter.hidden = YES;
    self.favorite.isADView = YES;
    self.focus.isADView = YES;
    self.collection.image = KImageNamed(@"home_video_collection_nor");
    
    [_favoriteNum setText:@"0"];
    [_collectionNum setText:@"0"];
    [_commentNum setText:@"0"];
    [_shareNum setText:@"更多"];
    
    UIView *subView = (UIView *)[_ADPlayView viewWithTag:1000];
    if ([subView superview]) {
        [subView removeFromSuperview];
    }
    if(videoModel.expressView != nil){
        BUNativeExpressAdView *view = videoModel.expressView;
        view.tag = 1000;
        [_ADPlayView addSubview:view];
    }
}


#pragma mark - SharePopViewDelegate
- (void)actionClickedAtIndex:(NSInteger)index type:(NSString *)type
{
    
}

/*第一版本*/
//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        CGSize size_now = frame.size;
//
//        self.hoem_recommend_playview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height-10)];
//        [self addSubview:self.hoem_recommend_playview];
//
//        self.hoem_recommend_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//        self.hoem_recommend_imageView.contentMode = UIViewContentModeScaleAspectFill;
//        self.hoem_recommend_imageView.clipsToBounds = YES;
//        [self addSubview:self.hoem_recommend_imageView];
//
//
//
//        UIView * colorView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height)];
//        CAGradientLayer * gradientLayer = [CAGradientLayer layer];
//        gradientLayer.frame = CGRectMake(0, size_now.height/2, size_now.width, size_now.height/2);
//        gradientLayer.colors = @[(__bridge id)COLOR_ALPH(0, 0, 0, 0).CGColor,(__bridge id)COLOR_ALPH(0, 0, 0, 0.5).CGColor];
//        gradientLayer.startPoint = CGPointMake(0, 0);
//        gradientLayer.endPoint = CGPointMake(0, 1);
//        gradientLayer.locations = @[@0,@1];
//        [colorView.layer addSublayer:gradientLayer];
//        [self addSubview:colorView];
//
//        UIView * colorView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, size_now.width, size_now.height)];
//        CAGradientLayer * gradientLayer1 = [CAGradientLayer layer];
//        gradientLayer1.frame = CGRectMake(0, 0, size_now.width, size_now.height/2);
//        gradientLayer1.colors = @[(__bridge id)COLOR_ALPH(0, 0, 0, 0.5).CGColor,(__bridge id)COLOR_ALPH(0, 0, 0, 0).CGColor];
//        gradientLayer1.startPoint = CGPointMake(0, 0);
//        gradientLayer1.endPoint = CGPointMake(0, 1);
//        gradientLayer1.locations = @[@0,@1];
//        [colorView1.layer addSublayer:gradientLayer1];
//        [self addSubview:colorView1];
//
//        self.hoem_recommend_playbutton = [[QzVideoPlayButtonView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
//        self.hoem_recommend_playbutton.hidden = YES;
//        [self addSubview:self.hoem_recommend_playbutton];
//
//
//        self.slider = [QZVideoPlaySliderView new];
//        [self addSubview:self.slider];
//        self.hoem_recommend_playview.jp_progressView = self.slider;
//    }
//    return self;
//}
//- (void)showPlayModel:(QZVideoModel *)model{
//
//}
//- (void)resumePlay:(NSString *)videoUrl{
//    BVideoCacheResult cacheResult = [[BVideoCacheTool tool] getVideoPathWithWebUrl:videoUrl];
////    if((self.playCacheResult.isLocalPath && !cacheResult.isLocalPath)){
//        [self playVideoWithUrl:videoUrl];//播放网络
////    }
////    else
////    {
////        [self.hoem_recommend_playview jp_resume];//播放缓存
////    }
//}
//- (void)stopPlayWithUrl:(NSString *)videoUrl{
//    //第一种：
//    [self.hoem_recommend_playview jp_stopPlay];
//}
//- (void)playVideoWithUrl:(NSString *)videoUrl{
//    /**第一种播放方式JPvideoPlay**/
//    NSLog(@"&&&&&&&&&&&11111传入原始播放地址:%@",videoUrl);
//    if (_isPause) {
//        return;
//    }
//    self.isOnePlayFinish = YES;
//    BVideoCacheResult cacheResult = [[BVideoCacheTool tool] getVideoPathWithWebUrl:videoUrl];
//    self.playCacheResult = cacheResult;
//    NSLog(@"&&&&&&&&&&&2222传入播放地址:%@",cacheResult.path);
//    NSURL *url = [NSURL URLWithString:cacheResult.path];
//    if(cacheResult.isLocalPath){
//        url = [NSURL fileURLWithPath:cacheResult.path];
//    }
//
//    [self.hoem_recommend_playview jp_playVideoMuteWithURL:url bufferingIndicator:nil progressView:nil configuration:^(UIView * _Nonnull view, JPVideoPlayerModel * _Nonnull playerModel) {
//        UIImage * image = self.hoem_recommend_imageView.image;
//        NSLog(@"%f===%f",self.hoem_recommend_imageView.image.size.width,self.hoem_recommend_imageView.image.size.height);
//        if (image) {
//            if (image.size.width>=image.size.height) {
//                playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
//            }else{
//                playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//            }
//        }else{
//            playerModel.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//        }
//    }];
//    self.hoem_recommend_playview.jp_videoPlayerDelegate = self;
//}
@end

